package com.seeyon.ctp.rest.resources;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.util.FieldInfo;
import com.seeyon.apps.ldmeeting.manager.MenuManager;
import com.seeyon.apps.schedule.manager.ScheduleManager;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.util.FlipInfo;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Map;

/**
 * Title:
 * Description: XX 项目**
 *
 * @author wxt.chenfan
 * @version 2024-11-28
 * @Date 2024-11-28
 */
@Path("schedule")
@Consumes(MediaType.APPLICATION_JSON)
@Produces({ MediaType.APPLICATION_JSON })
public class ScheduleResource extends BaseResource {
    private ScheduleManager scheduleManager = (ScheduleManager) AppContext.getBean("scheduleManager");

    /**
     * Title: getLeaveAmount
     * Description: 获取请假数量列表
     * @author wxt.chenfan
     * @date: 2024/11/28
     * @return: com.alibaba.fastjson.JSONObject
     */
    @Path("getLeaveNum")
    @POST
    @Consumes({ MediaType.APPLICATION_JSON })
    @Produces(MediaType.APPLICATION_JSON)
    public Response getLeaveNum(JSONObject params){
        JSONObject object = new JSONObject();
        if (params.get("date") == null){
            object.put("code",400);
            object.put("msg","查询失败");
            return returnResult(object);
        }
        object = scheduleManager.getLeaveNum(params);
        return returnResult(object);
    }

    /**
     * Title: getLeaveDetails
     * Description: 获取请假详情
     * @author wxt.chenfan
     * @date: 2024/11/28
     * @return: com.alibaba.fastjson.JSONObject
     */
    @Path("getLeavedetails")
    @POST
    @Consumes({ MediaType.APPLICATION_JSON })
    @Produces(MediaType.APPLICATION_JSON)
    public Response getLeavedetails(Map<String, Object> params){
        JSONObject object = new JSONObject();
        if (params.get("date") == null || params.get("page") == "" || params.get("size") == null){
            object.put("code",400);
            object.put("msg","请传递参数");
            return returnResult(object);
        }
        FlipInfo flipInfo = new FlipInfo();
        flipInfo.setSize(Integer.parseInt(String.valueOf(params.get("size"))));
        flipInfo.setPage(Integer.parseInt(String.valueOf(params.get("page"))));
        flipInfo = scheduleManager.getLeavedetails(flipInfo,params);
        object.put("code",200);
        object.put("msg","查询成功");
        object.put("data",flipInfo);
        return returnResult(object);
    }

    /**
     * 返回值
     * <p>Title: returnResult
     * <p>Description: TODO
     * wxt.mengchun
     * @date 2024年7月31日 上午11:09:34
     * @param object
     * @return
     */
    private Response returnResult(JSONObject object) {
        int code = object.getInteger("code");
        String msg = object.getString("msg");
        if (code == 200) {
            return success(object.get("data"), msg, code);
        }else {
            return fail(msg, code);
        }
    }
}
